package com.jia.interviewPro;

/**
 * @program: Leetcode
 * @description: https://leetcode-cn.com/problems/get-kth-magic-number-lcci/comments/
 * @author: STU756
 * @create: 2020-09-04 11:25
 */
public class Pro1709 {
    public int getKthMagicNumber(int k) {
        if(k <= 0) return 0;
        if(k == 1) return 1;
        int[] f = new int[k+1];
        f[1] = 1;
        int index3 = 1, index5 = 1, index7 = 1;
        int num = 0;
        for(int i = 2; i <= k; i++) {
            f[i] = Math.min(Math.min(f[index3] * 3, f[index5] * 5), f[index7] * 7);
            if(f[i] == f[index3] * 3) {
                ++index3;
            }
            if(f[i] == f[index5] * 5) {
                ++index5;
            }
            if(f[i] == f[index7] * 7) {
                ++index7;
            }
        }
        return f[k];
    }
}
